package com.apes.fn.tms.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.stock.model.PhyDepot;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;


/**
 * 功能：支线班次信息
 *
 * @author Linwz
 * @create 2020-03-06 9:46
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = BranchShift.CONST_TABLE_NAME)
public class BranchShift extends Model {
    public static final String CONST_TABLE_NAME = "tms_branch_shift";

    @Id
    @Column(name = "id", length = 10)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "编码")
    @Comment("编码")
    private String id;

//    @Name
//    @Column(name = "name", length = 30)
//    @Comment("名称")
//    private String name;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "site_id", referencedColumnName = "id")
    @Comment("站点")
    private Site site;  //站点


    @OneToMany(mappedBy = "branchShift", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<BranchShiftItem> branchShiftItems = new ArrayList<>(); //支线线路明细信息

    public List<BranchShiftItem> getBranchShiftItems() {
        for (BranchShiftItem item : branchShiftItems) {
            item.setBranchShift(this);
        }
        return branchShiftItems;
    }



}
